<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>欢迎页面-L-admin1.0</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" href="../css/font1.css">
  <link rel="stylesheet" href="../css/xadmin.css">
  <link rel="stylesheet" href="../css/page.css">
  <script src="../js/jquery.min.js"></script>
  <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="../js/xadmin.js"></script>
  <script type="text/javascript" src="../js/page.js"></script>
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>

  <![endif]-->
</head>

<body class="layui-anim layui-anim-up">

<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
  <a class="layui-btn layui-btn-primary layui-btn-small" onclick="refresh()" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:38px">ဂ</i></a>
</div>
<div class="x-body">
  <div class="layui-row">
    <form class="layui-form layui-col-md12 x-so" >
    <!--<form class="layui-form layui-col-md12 x-so" action="">-->
      <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input" style="height: 38px;">
      <!--<button class="layui-btn"  type="submit" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>-->
      <button class="layui-btn" lay-submit lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
    <!--</form>-->
    </form>

  </div>
  <xblock>
    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
    <button class="layui-btn" onclick="x_admin_show('添加用户','./member-add.html',600,400)"><i class="layui-icon"></i>添加</button>
    <span class="x-right" id="span_id" style="line-height:40px"></span>
  </xblock>
  <table class="layui-table" >
    <thead>
    <tr>
      <th>
        <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
      </th>
      <!--<th>-->
        <!--<input type='checkbox' id="checkAll"/>-->
      <!--</th>-->
      <th>ID</th>
      <th>用户名</th>
      <th>性别</th>
      <th>手机</th>
      <th>邮箱</th>
      <th>地址</th>
      <th>加入时间</th>
      <th>状态</th>
      <th>操作</th></tr>
    </thead>
    <tbody id="tbodyId">
    </tbody>
  </table>
  <!-- 分页 -->
  <div class="paging mt30">
    <ul id="page">
      <li>
        <a>上一页</a>
      </li>
      <li>
        <a>首页</a>
      </li>
      <li>
        <a>末页</a>
      </li>
      <li>
        <a class="borderNone">下一页</a>
      </li>
    </ul>
  </div>
  <!--<div id=pageId class="page">
  <div>
    <a class="prev" onclick="first()" >&lt;&lt;</a>
    <a id="one1" class="num" href="">1</a>
    <span id="one2" class="current">2</span>
    <a id="one3" class="num"  href="">3</a>
    <a id="pangCount" class="num" href="">489</a><strong></strong>
    <a class="next" onclick="next()">&gt;&gt;</a>
  </div>
</div>-->
</div>
</body>
<script type="text/javascript">

    /* 		//异步发起请求获取记录信息
            //1.定义的url
            var url="user/doFindPageObjects"
            var pageCurrent=$(#pangCount).data("pangCount")
            //2.发起异步请求出来结果 */

    $(function(){
        //分页插件初始花页面值
        getObjects();
    });
    //刷新按钮
    function refresh() {
        getObjects;
    }

    function getObjects(){
        //请求参数
        var params={"pageCurrent":currentPage};//dsafafadsfsadfsd
        console.log(params);
        //请求url
        var url="/user/doFindPageObjects";
        $.get(url,params,doHandleResponseResult)
    }
    //处理响结果
    function doHandleResponseResult(result) {
        $("#span_id").html("共有数据："+result.data.rowCount+ "条")
         console.log("result",result);
        if (result.state==1) {

            //初始化页面上的日志
            doSetTableBodyRows(result.data.records);//获取到records的值
            //初始化分页页面上的信息
            totalPage = result.data.pageCount;
            //console.log(result);
            step();//dsafafadsfsadfsd
        }else {
            alert(result.message)
        }
    }
    //初始化用户信息
    function doSetTableBodyRows(records){
        //获取tbody内容并清空
        var tBody=$("#tbodyId");
        tBody.empty();//清空内容
        //迭代内容刷新数据
        for(var i=0;i<records.length;i++){
            //创建一个tr对象
            var tr=$("<tr></tr>");
            //创建多个td对象
            var tds=doCreateTds(records[i]);
            //将td追加到tr中
            tr.append(tds)
            //将tr追加到tbody中
            tBody.append(tr)

        }
       /* layui_form_checkbox();*/

        //member_stop(this,'10001')'
        //创建当前的多个对象
        function doCreateTds(row){
            console.log("row",row)
            var tds="<td>"+
                "<div class='layui-unselect layui-form-checkbox' lay-skin='primary' data-id="+row.id+">"+"<i class='layui-icon'>&#xe605;</i>"+"</div>"+
                "</td>"+
                // "<td>"+ "<input type='checkbox' id='cBox' value='"+row.id+"'/>"+ "</td>"+
                "<td>"+row.id+"</td>"+
                "<td>"+row.username+"</td>"+
                "<td>"+row.gender+"</td>"+
                "<td>"+row.mobile+"</td>"+
                "<td>"+row.email+"</td>"+
                "<td>"+row.site+"</td>"+
                "<td>"+row.createdTime+"</td>"+
                "<td class='td-status'>"+
                "<span class='layui-btn layui-btn-normal layui-btn-sm'>"+(row.valid?"已启用":"已停用")+"</span>"+"</td>"+
                "<td class='td-manage'>"+
                "<a onclick=\"member_stop(this,"+row.id+")\" class='layui-btn layui-btn-sm layui-btn-primary' href='javascript:;'  title='启用'>"+
                "修改状态"+
                "</a>"+
                "<a title='删除' class='layui-btn layui-btn-sm layui-btn-danger' onclick=\"member_del(this," +row.id+ ")\" href='javascript:;'>"+
                "删除"+
                "</a>"+
                "</td>"

            return tds
        }
    }

    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(sreach)', function(data){
            //请求参数
            var params={"pageCurrent":currentPage,"username":data.field.username,"start":data.field.start,"end":data.field.end};//dsafafadsfsadfsd
            //请求url
            var url="/user/doFindPageObjects";
            $.get(url,params,doHandleResponseResult)
            return false;
        });
    });

    /*用户-停用*/
    function member_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){

            if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已启用!',{icon: 5,time:1000});
                //请求参数
                var params={"id":id,"valid":0};
                //请求url
                var url="/user/doValidById";
                $.get(url,params)
            }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');
                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
                //请求参数
                var params={"id":id,"valid":1};
                //请求url
                var url="/user/doValidById";
                $.get(url,params)
            }
        });
    }
    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            //请求参数
            var params={"ids":id};

            //请求url
            var url="/user/doDeleteObjects";
            $.get(url,params);
            getObjects();
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1500});
        });
    }
    //批量删除
    function delAll (argument) {
        var data = tableCheck.getData();
        if (data.length!=0) {
        layer.confirm('确认要删除id为&ensp;'+data+'&ensp;的信息吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            var url="/user/doDeleteObjects"
            var ids={"ids":data.toString()};
            $.get(url,ids);
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
            getObjects()
        });
        }else {
            alert("请选则")
        }
    }
</script>

</html>
